package logic

import (
	"context"
	"strconv"
	"taobao/taobaoclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.AddCartRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.TaoRpc.GoodsAdd(l.ctx, &taobaoclient.AddCartRequest{
		UserId:     int64(req.UserId),
		GoodsTitle: req.GoodsTitle,
		GoodsPrice: req.GoodsPrice,
		Stock:      int64(req.Stock),
		GoodsCover: req.GoodsCover,
		Status:     strconv.Itoa(req.Status),
		CheckStaus: int64(req.CheckStaus),
		GoodsId:    int64(req.GoodSId),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "添加成功",
		Data: add,
	}, nil
}
